'use strict';

/**
 * @ngdoc directive
 * @name jgappApp.directive:checkuserDefine
 * @description
 * # checkuserDefine
 */
angular.module('jgappApp')
    .directive('checkuserDefine', function() {
        return {
            scope: {
                fieldMap: "=fieldMap"
            },
            template: '<div class="item-userDefined mt10" ng-show="fieldMap">' +
                '<p class="list-label c-blue">自定义字段</p>' +
                '<div class="list-item flex" ng-repeat="item in formData" ng-class={"mt0":$first}>' +
                '<div class="w35 c9">' +
                '{{item.fieldLabel}}:' +
                '</div>' +
                '<div class="w65">' +
                '{{item.value}}' +
                '</div>' +
                '</div>' +
                '</div>',
            restrict: 'AE',
            replace: true,
            link: function postLink(scope, element, attrs) {
                var init = function() {
                    // 如果是审批页面只做展示
                    scope.$watch('fieldMap', function(newValue, oldValue) {
                        if (scope.fieldMap) {
                            var fieldMapObj = JSON.parse(scope.fieldMap)
                            scope.formData = angular.extend(fieldMapObj, {})
                        }
                    });
                }
                init()
            }
        };
    });
